import Vue from 'vue'

const LoginConstructor = Vue.extend(require('./loginModal.vue')) // 直接将Vue组件作为Vue.extend的参数

let nId = 1;

let instance;

const LoginModal = (options) => {
    let id = 'lm-' + nId++

    const LoginInstance = new LoginConstructor({
        data: options
    }) // 实例化一个带有content内容的LoginModal

    LoginInstance.id = id
    LoginInstance.vm = LoginInstance.$mount() // 挂载但是并未插入dom，是一个完整的Vue实例
    LoginInstance.vm.visible = true
    LoginInstance.dom = LoginInstance.vm.$el
    document.body.appendChild(LoginInstance.dom) // 将dom插入body
    LoginInstance.dom.style.zIndex = nId + 1001 // 后插入的Notice组件z-index加一，保证能盖在之前的上面

    return LoginInstance
}
LoginModal.show = () => {
    if (instance === undefined){
        instance = LoginModal();
    }
    
    instance.showModal();
};

export default LoginModal